package com.gaohe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaohe.mapper.ClassesMapper;
import com.gaohe.mapper.UserClassMapper;
import com.gaohe.pojo.Classes;
import com.gaohe.pojo.UserClass;
import com.gaohe.service.ClassesService;
import com.gaohe.service.UserClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserClassServiceImpl extends ServiceImpl<UserClassMapper, UserClass> implements UserClassService {
    @Autowired
    private ClassesMapper classesMapper;
    @Override
    public long getClassesTotalCount(Long id){
        LambdaQueryWrapper<Classes> qw = new LambdaQueryWrapper<>();
        qw.eq(Classes::getTeacherId,id);
        long count = classesMapper.selectCount(qw);
        return count;
    }

    @Override
    public long getMouthTotal(Long id) {
        LambdaQueryWrapper<Classes> qw = new LambdaQueryWrapper<>();
        qw.eq(Classes::getTeacherId,id);
        long count = classesMapper.selectCount(qw);
        //当前月初
        LocalDateTime time1=LocalDateTime.of(LocalDateTime.now().getYear(),LocalDateTime.now().getMonth(),
                1,0,0);
        //当前月末
        LocalDateTime time2=LocalDateTime.of(LocalDateTime.now().getYear(),
               LocalDateTime.now().getMonth(), LocalDateTime.now().getDayOfMonth(),0,0
        );
        LambdaQueryWrapper<Classes> qw1 = new LambdaQueryWrapper<>();
        qw.eq(Classes::getTeacherId,id);
        qw.between(Classes::getCreateTime,time1,time2);
        long count1 = classesMapper.selectCount(qw);
        return count1;

    }

}
